package com.slz3.business.module.goodsManagement.gooBaseGoodsAttribute.steward;

import com.slz3.business.frame.redis.RedisKey;
import com.slz3.business.frame.util.VE;
import com.slz3.business.module.goodsManagement.gooBaseGoodsAttribute.domain.GooBaseGoodsAttribute;

import java.util.*;

import static java.util.stream.Collectors.toList;

public class GooBaseGoodsAttributeConverter {
    public static Map<UUID, List<GooBaseGoodsAttribute>> listToListMap(List<GooBaseGoodsAttribute> attrList) {
        if (VE.isEmpty(attrList)) {
            return null;
        }
        Map<UUID, List<GooBaseGoodsAttribute>> listMap = new HashMap<>();
        attrList.forEach(item -> {
            UUID key = item.getFkBaseGoodsUUID();
            List<GooBaseGoodsAttribute> value = listMap.get(key);
            if (value == null) {
                value = new ArrayList<>();
                listMap.put(key, value);
            }
            value.add(item);
        });
        return listMap;
    }

    public static Map<String, List<String>> mapToRULMap(Map<UUID, List<GooBaseGoodsAttribute>> attrListMap) {
        if (VE.isEmpty(attrListMap)) {
            return null;
        }
        Map<String, List<String>> map = new HashMap<>();
        attrListMap.entrySet().stream().forEach(item -> {
            String key = RedisKey.gooBaseGoodsAttribute.uuidSetByUpper(item.getKey());
            List<String> value = item.getValue().stream().map(it -> it.getUuid().toString()).collect(toList());
            map.put(key, value);
        });
        return map;
    }
}
